﻿module Selection

open FsFlow

type ViewModel = 
    {
        AllNums      : int PublishedSet
        SelectedNums : int PublishedSet
        Count        : int Published
        Sum          : int Published
        Product      : string Published
    }

let createViewModel() =
    let allNums = Flow.set (set {1 .. 20})
    let selectedNums = Flow.set (set {4 .. 6})

    let count = selectedNums |> Flow.map Set.count
    let sum = selectedNums |> Flow.reduceSet 0 (+) (-)
    let product = selectedNums |> Flow.reduceSet 1I (fun a b -> a * bigint b) (fun a b -> a / bigint b)
    let productStr = product |> Flow.map string

    {
        AllNums      = allNums |> Flow.publishSet
        SelectedNums = selectedNums |> Flow.publishSet
        Count        = count |> Flow.publish   
        Sum          = sum |> Flow.publish       
        Product      = productStr |> Flow.publish    
    }